<template>
  <BasicForm @register="registerForm" @submit="handleSubmit" />
</template>

<script lang="ts" setup>
  import { onMounted } from "vue";
  import { useForm } from "/@/components/Form";
  import { leardWorkFormSchema } from "../task.data";
  import { useMessage } from "/@/hooks/web/useMessage";
  import BasicForm from "/@/components/Form/src/BasicForm.vue";
  import { defaultFormSettings } from "/@/hooks/core/useDefault";
  import { getLeaderWorkInfoApi, saveOrUpdateLeaderWorkApi } from "/@/api/core/leaderWork";

  const [registerForm, { setFieldsValue, setProps }] = useForm({
    labelWidth: 80,
    schemas: leardWorkFormSchema,
    ...defaultFormSettings,
  });

  const { createMessage } = useMessage();

  async function handleSubmit(value) {
    try {
      await setProps({
        submitButtonOptions: {
          loading: true,
        },
      });
      await saveOrUpdateLeaderWorkApi(value);
      createMessage.success("班主任实习工作记录提交成功");
    } finally {
      await setProps({
        submitButtonOptions: {
          loading: false,
        },
      });
    }
  }

  onMounted(async () => {
    await setFieldsValue({ ...(await getLeaderWorkInfoApi()) });
  });
</script>

<style>
  .ant-form-item-label {
    white-space: normal !important;
  }
</style>
